package guda.shop.cms.manager.impl;

import guda.shop.cms.dao.AddressDao;
import guda.shop.cms.entity.Address;
import guda.shop.cms.manager.AddressMng;
import guda.shop.common.hibernate3.Updater;
import guda.shop.common.page.Pagination;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class AddressMngImpl
        implements AddressMng {
    private AddressDao addressDao;

    public List<Address> getListById(Long paramLong) {
        return this.addressDao.getListById(paramLong);
    }

    @Transactional(readOnly = true)
    public Pagination getPage(int paramInt1, int paramInt2) {
        Pagination localPagination = this.addressDao.getPage(paramInt1, paramInt2);
        return localPagination;
    }

    public Pagination getPageByParentId(Long paramLong, int paramInt1, int paramInt2) {
        Pagination localPagination = this.addressDao.getPageByParentId(paramLong, paramInt1, paramInt2);
        return localPagination;
    }

    @Transactional(readOnly = true)
    public Address findById(Long paramLong) {
        Address localAddress = this.addressDao.findById(paramLong);
        return localAddress;
    }

    public Address save(Address paramAddress) {
        this.addressDao.save(paramAddress);
        return paramAddress;
    }

    public Address update(Address paramAddress) {
        Updater localUpdater = new Updater(paramAddress);
        Address localAddress = this.addressDao.updateByUpdater(localUpdater);
        return localAddress;
    }

    public Address deleteById(Long paramLong) {
        Address localAddress = this.addressDao.deleteById(paramLong);
        return localAddress;
    }

    public Address[] deleteByIds(Long[] paramArrayOfLong) {
        Address[] arrayOfAddress = new Address[paramArrayOfLong.length];
        int i = 0;
        int j = paramArrayOfLong.length;
        while (i < j) {
            arrayOfAddress[i] = deleteById(paramArrayOfLong[i]);
            i++;
        }
        return arrayOfAddress;
    }

    public Address[] updatePriority(Long[] paramArrayOfLong, Integer[] paramArrayOfInteger) {
        Address[] arrayOfAddress = new Address[paramArrayOfLong.length];
        int i = 0;
        int j = paramArrayOfLong.length;
        while (i < j) {
            arrayOfAddress[i] = findById(paramArrayOfLong[i]);
            arrayOfAddress[i].setPriority(paramArrayOfInteger[i]);
            i++;
        }
        return arrayOfAddress;
    }

    @Autowired
    public void setDao(AddressDao paramAddressDao) {
        this.addressDao = paramAddressDao;
    }
}

